package com.xjy.web.controller.system.basics;

import com.xjy.common.annotation.Log;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.enums.BusinessType;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.system.domain.bo.SysImageTypeAddBo;
import com.xjy.system.domain.bo.SysImageTypeEditBo;
import com.xjy.system.domain.bo.SysImageTypeQueryBo;
import com.xjy.system.domain.vo.SysImageTypeVo;
import com.xjy.system.service.ISysImageTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 影像类别信息Controller
 *
 * @author zc
 * @date 2022-02-07
 */
@Api(value = "影像类别信息控制器", tags = {"影像类别信息管理"})
//@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/imagetype")
public class SysImageTypeController extends BaseController {


	@Autowired
	private ISysImageTypeService iSysImageTypeService;

	/**
	 * 查询影像类别信息列表
	 */
	@ApiOperation("查询影像类别信息列表")
	@PreAuthorize("@ss.hasPermi('system:imagetype:list')")
	@GetMapping("/list")
	public TableDataInfo<SysImageTypeVo> list(@Validated SysImageTypeQueryBo bo) {
		return iSysImageTypeService.queryPageList(bo);
	}

	/**
	 * 导出影像类别信息列表
	 */
	@ApiOperation("导出影像类别信息列表")
	@PreAuthorize("@ss.hasPermi('system:imagetype:export')")
	@Log(title = "影像类别信息", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult<SysImageTypeVo> export(@Validated SysImageTypeQueryBo bo) {
		List<SysImageTypeVo> list = iSysImageTypeService.queryList(bo);
		ExcelUtil<SysImageTypeVo> util = new ExcelUtil<SysImageTypeVo>(SysImageTypeVo.class);
		return util.exportExcel(list, "影像类别信息");
	}

	/**
	 * 获取影像类别信息详细信息
	 */
	@ApiOperation("获取影像类别信息详细信息")
	@PreAuthorize("@ss.hasPermi('system:imagetype:query')")
	@GetMapping("/{id}")
	public AjaxResult<SysImageTypeVo> getInfo(@NotNull(message = "主键不能为空")
											  @PathVariable("id") Long id) {
		return AjaxResult.success(iSysImageTypeService.queryById(id));
	}

	/**
	 * 新增影像类别信息
	 */
	@ApiOperation("新增影像类别信息")
	@PreAuthorize("@ss.hasPermi('system:imagetype:add')")
	@Log(title = "影像类别信息", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody SysImageTypeAddBo bo) {
		return toAjax(iSysImageTypeService.insertByAddBo(bo) ? 1 : 0);
	}

	/**
	 * 修改影像类别信息
	 */
	@ApiOperation("修改影像类别信息")
	@PreAuthorize("@ss.hasPermi('system:imagetype:edit')")
	@Log(title = "影像类别信息", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping()
	public AjaxResult<Void> edit(@Validated @RequestBody SysImageTypeEditBo bo) {
		return toAjax(iSysImageTypeService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除影像类别信息
	 */
	@ApiOperation("删除影像类别信息")
	@PreAuthorize("@ss.hasPermi('system:imagetype:remove')")
	@Log(title = "影像类别信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iSysImageTypeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
	}
}
